<?php 
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
	$rows_per_page = 20;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	
$listpassrequest = mysql_query("select ID, Username, Email, `Comment`, CreatedDate, `Status` from request_password order by CreatedDate desc limit ".$page_start.",".$rows_per_page);
$listpassrequestPage = mysql_query("select ID from request_password order by CreatedDate desc ");


$number_of_page = ceil ( mysql_num_rows( $listpassrequestPage ) / $rows_per_page );
?>

<script type="text/javascript">

function paging(page, search_str){
	var l_reset = $('input#l_reset').val();
	var l_delete = $('input#l_delete').val();
	$.ajax({url:"admin/employeemanagement/ajaxpagingrequestchagepass.php", data : {pages : page , l_reset : l_reset, l_delete : l_delete}, success:function(result){
		$("table#listRequest tr:not(:first)").remove();
		$("table#listRequest thead").append(result);
	}});
}

function deleterequest(ids){
	var l_reset = $('input#l_reset').val();
	var l_delete = $('input#l_delete').val();
	$.ajax({url:"admin/employeemanagement/ajaxdeleterequestchagepass.php", data : {ids : ids , l_reset : l_reset, l_delete : l_delete}, success:function(result){
		$("table#listRequest tr:not(:first)").remove();
		$("table#listRequest thead").append(result);
	}});
	
}


function generatepass(plength){
	var keylist="abcdefghijklmnopqrstuvwxyz123456789";
	temp='';
	for (var i=0;i<plength;i++)
	temp+=keylist.charAt(Math.floor(Math.random()*keylist.length));
	return temp;
}

function resetrequest(page,ids,ele){
	var l_reset = $('input#l_reset').val();
	var l_delete = $('input#l_delete').val();
	var usernames = $(ele).parent().parent().find("[name='username']").html();
	var passwords = generatepass(5);
	$.ajax({url:"admin/employeemanagement/ajaxresetrequestchagepass.php", data : {pages : page , ids : ids , passwords : passwords , usernames : usernames , l_reset : l_reset, l_delete : l_delete}, success:function(result){
		$("table#listRequest tr:not(:first)").remove();
		$("table#listRequest thead").append(result);
	}});
	
}

</script>

<div id="contains" style="background-color: #edf4f7;">
	<div class="title">
		<div
			style="color: #0962C8; font-size: 12px; font-weight: bold; padding-left: 2px; padding-top: 8px; text-transform: uppercase;"></div>
	</div>
	<div class="body" style="margin-left: 5px;margin-right:5px">
		<form id="form1" name="form1" method="post" action="" enctype="">
			<!-- div class="navigation-button">
				<a onclick="javascript: history.go(-1);"><img src="images/back-admin.png" />
				</a>
				<div>Back</div>
			</div-->
			<br style="clear: both" />
			<br />
			<input type="hidden" value="<? echo 'Reset';?>" id="l_reset"/>	
			<input type="hidden" value="<? echo 'Delete';?>" id="l_delete"/>		
			<table id="listRequest" class="rf-dt" style="width: 100%;">
				<colgroup span="6"></colgroup>
				<thead class="rf-dt-thd">
					<tr class="rf-dt-shdr">
						<th class="rf-dt-shdr-c" scope="col" width="10%" style="background-color: #eeeeee;"><?php echo $l_status?></th>
						<th class="rf-dt-shdr-c" scope="col" width="8%" style="background-color: #eeeeee;"><?php echo $l_no?></th>
						<th class="rf-dt-shdr-c" scope="col" width="20%" style="background-color: #eeeeee;"><?php echo $l_username?></th>
						<th class="rf-dt-shdr-c" scope="col" width="30%" style="background-color: #eeeeee;"><?php echo $l_email?></th>
						<th class="rf-dt-shdr-c" scope="col" width="15%" style="background-color: #eeeeee;"><?php echo $l_created_date?></th>
						<th class="rf-dt-shdr-c" scope="col" width="17%" style="background-color: #eeeeee;"></th>
					</tr>
					<?php 
					$i_reps = 1;
					while ($row = mysql_fetch_array($listpassrequest)) {
						
					?>
					<tr>
						<td class="rf-dt-c" style="font-size: 12px;text-align: center ;" scope="col"><?if ($row[Status]==0) {?>
							<img src ="images/sad.png"/>
						<?php }else{?> <img src ="images/check.png"/><?php }?></td>
						<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?=$i_reps?></td>
						<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col" name="username"><?=$row[Username]?></td>
						<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?=$row[Email]?></td>
						<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?=$row[CreatedDate]?></td>
						<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col">
						<input id="reset" name="reset" style="width: 69px !important" onclick="resetrequest(<?=$page?>,<?=$row[ID]?>,this)" value="<?echo $l_reset?>" 
							<?if ($row[Status]==1) {?> disabled="disabled" class="buttonNormalDisable"	<?php }else{?> class="buttonNormal"<?php } ?> type="button" />
						<input id="delete" name="delete" style="width: 70px !important" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){deleterequest(<?=$row[ID]?>)}" value="<?echo $l_delete?>"
							 class="buttonNormal" type="button" />
						</td>
					</tr>
					<?php
					$i_reps +=1;
					}
					?>
					<tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="9">
	                        	<div style="text-align: center; width: 100%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page)
																	$p=$number_of_page-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="paging(1,'')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="paging(<?=($page-1)?>,'')" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="paging(<?=$i?>,'')" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page){ ?>
																		<a onclick="paging(<?=($page+1)?>,'')"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="paging(<?=($number_of_page)?>,'')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr>
				</thead>
		</table>
		</form>

	</div>
</div>
